<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>视差滚动轮播</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f0f0f0;
            overflow: hidden;
        }

        .parallax-carousel {
            width: 800px;
            height: 500px;
            position: relative;
            overflow: hidden;
        }

        .parallax-container {
            width: 100%;
            height: 100%;
            position: relative;
        }

        .parallax-slide {
            position: absolute;
            width: 100%;
            height: 100%;
            opacity: 0;
            transition: opacity 0.8s ease;
        }

        .parallax-slide.active {
            opacity: 1;
        }

        .parallax-layer {
            position: absolute;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        .parallax-layer img {
            width: 120%;
            height: 120%;
            object-fit: cover;
            position: absolute;
            left: -10%;
            top: -10%;
            transition: transform 0.8s ease;
        }

        .layer-1 { z-index: 1; opacity: 0.3; }
        .layer-2 { z-index: 2; opacity: 0.6; }
        .layer-3 { z-index: 3; }

        .controls {
            position: fixed;
            bottom: 20px;
            display: flex;
            gap: 10px;
            z-index: 100;
        }

        .control-btn {
            padding: 10px 20px;
            background: #333;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .control-btn:hover {
            background: #555;
        }

        .parallax-indicators {
            position: absolute;
            bottom: 40px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 10px;
            z-index: 100;
        }

        .indicator {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: rgba(255,255,255,0.5);
            cursor: pointer;
            transition: background 0.3s;
        }

        .indicator.active {
            background: white;
        }
    </style>
</head>
<body>
    <div class="parallax-carousel">
        <div class="parallax-container">
            <div class="parallax-slide active">
                <div class="parallax-layer layer-1">
                    <img src="../img/1 (1).png" alt="Background 1">
                </div>
                <div class="parallax-layer layer-2">
                    <img src="../img/1 (2).png" alt="Middle 1">
                </div>
                <div class="parallax-layer layer-3">
                    <img src="../img/1 (3).png" alt="Front 1">
                </div>
            </div>
            <div class="parallax-slide">
                <div class="parallax-layer layer-1">
                    <img src="../img/1 (4).png" alt="Background 2">
                </div>
                <div class="parallax-layer layer-2">
                    <img src="../img/1 (5).png" alt="Middle 2">
                </div>
                <div class="parallax-layer layer-3">
                    <img src="../img/1 (6).png" alt="Front 2">
                </div>
            </div>
            <div class="parallax-slide">
                <div class="parallax-layer layer-1">
                    <img src="../img/1 (7).png" alt="Background 3">
                </div>
                <div class="parallax-layer layer-2">
                    <img src="../img/1 (1).png" alt="Middle 3">
                </div>
                <div class="parallax-layer layer-3">
                    <img src="../img/1 (2).png" alt="Front 3">
                </div>
            </div>
        </div>
        <div class="parallax-indicators"></div>
    </div>
    <div class="controls">
        <button class="control-btn prev">上一张</button>
        <button class="control-btn next">下一张</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const container = document.querySelector('.parallax-container');
            const slides = document.querySelectorAll('.parallax-slide');
            const prevBtn = document.querySelector('.prev');
            const nextBtn = document.querySelector('.next');
            const indicators = document.querySelector('.parallax-indicators');
            
            let currentIndex = 0;
            const totalSlides = slides.length;
            let isAnimating = false;

            // Create indicators
            slides.forEach((_, index) => {
                const indicator = document.createElement('div');
                indicator.className = `indicator ${index === 0 ? 'active' : ''}`;
                indicator.addEventListener('click', () => {
                    if (!isAnimating && currentIndex !== index) {
                        updateCarousel(index);
                    }
                });
                indicators.appendChild(indicator);
            });

            function updateCarousel(newIndex) {
                if (isAnimating) return;
                isAnimating = true;

                const direction = newIndex > currentIndex ? 1 : -1;
                const currentSlide = slides[currentIndex];
                const nextSlide = slides[newIndex];

                // Update indicators
                indicators.children[currentIndex].classList.remove('active');
                indicators.children[newIndex].classList.remove('active');

                // Animate layers
                const currentLayers = currentSlide.querySelectorAll('.parallax-layer img');
                const nextLayers = nextSlide.querySelectorAll('.parallax-layer img');

                currentLayers.forEach((layer, i) => {
                    const offset = (i + 1) * 10 * direction;
                    layer.style.transform = `translateX(${offset}%)`;
                });

                nextLayers.forEach((layer, i) => {
                    const offset = (i + 1) * -10 * direction;
                    layer.style.transform = `translateX(${offset}%)`;
                    setTimeout(() => {
                        layer.style.transform = 'translateX(0)';
                    }, 50);
                });

                // Update slides
                currentSlide.classList.remove('active');
                nextSlide.classList.add('active');

                setTimeout(() => {
                    currentIndex = newIndex;
                    indicators.children[currentIndex].classList.add('active');
                    isAnimating = false;
                }, 800);
            }

            prevBtn.addEventListener('click', () => {
                if (!isAnimating) {
                    const newIndex = (currentIndex - 1 + totalSlides) % totalSlides;
                    updateCarousel(newIndex);
                }
            });

            nextBtn.addEventListener('click', () => {
                if (!isAnimating) {
                    const newIndex = (currentIndex + 1) % totalSlides;
                    updateCarousel(newIndex);
                }
            });

            // Add mouse parallax effect
            document.addEventListener('mousemove', (e) => {
                if (!isAnimating) {
                    const activeSlide = slides[currentIndex];
                    const layers = activeSlide.querySelectorAll('.parallax-layer img');
                    const xPercent = (e.clientX / window.innerWidth - 0.5) * 2;
                    const yPercent = (e.clientY / window.innerHeight - 0.5) * 2;

                    layers.forEach((layer, index) => {
                        const factor = (index + 1) * 2;
                        layer.style.transform = `translate(${xPercent * factor}%, ${yPercent * factor}%)`;
                    });
                }
            });

            // Auto play
            setInterval(() => {
                if (!isAnimating) {
                    const newIndex = (currentIndex + 1) % totalSlides;
                    updateCarousel(newIndex);
                }
            }, 5000);
        });
    </script>
</body>
</html>